package org.redis.cluster.transport.netty.server;

import org.redis.cluster.transport.session.Session;
import org.redis.cluster.transport.session.SessionContext;

import io.netty.channel.ChannelHandlerContext;

public class NettyServerSession implements Session {
	
	private ChannelHandlerContext channelHandlerContext;
	private SessionContext context;
	
	public NettyServerSession(ChannelHandlerContext channelHandlerContext,SessionContext context) {
		this.channelHandlerContext=channelHandlerContext;
		this.context=context;
	}

	@Override
	public boolean write(Object data) {
		channelHandlerContext.write(data);
		return true;
	}
	
	@Override
	public boolean writeAndFlush(Object data) {
		channelHandlerContext.writeAndFlush(data);
		return true;
	}
	
	@Override
	public boolean flush() {
		channelHandlerContext.flush();
		return true;
	}

	@Override
	public SessionContext getContext() {
		return context;
	}

	@Override
	public boolean close() {
		channelHandlerContext.close();
		return true;
	}
	
	@Override
	public String getRemoteAddress() {
		return channelHandlerContext.channel().remoteAddress().toString().substring(1);
	}
}